//
//  MainMusicHeaderView.m
//  WXMusic
//
//  Created by 漫步人生路 on 15/8/31.
//  Copyright (c) 2015年 漫步人生路. All rights reserved.
//

#import "MainMusicHeaderView.h"

@implementation MainMusicHeaderView
- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSMutableArray *)imageArray delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        NSMutableArray *insterArray = [NSMutableArray arrayWithArray:imageArray];
        
        //讲imageArray最后一张图片插入到insterArray的第0位
        [insterArray insertObject:[imageArray objectAtIndex:imageArray.count - 1] atIndex:0];
        //将imageArray第0张图片插入到最后
        [insterArray insertObject:[imageArray objectAtIndex:0] atIndex:insterArray.count];
        //设置ScrollerView的contentSize
        self.contentSize = CGSizeMake(kWidth * [insterArray count], 0);
        self.pagingEnabled = YES;
        self.showsHorizontalScrollIndicator = YES;
        self.bounces = NO;
        self.delegate = delegate;
        self.contentOffset = CGPointMake(kWidth, 0);
        //循环创建ImageView
        for (int i = 0; i < insterArray.count; i ++) {
            TapImageView *touchImage = [[TapImageView alloc]initWithFrame:CGRectMake(kWidth * i, 0, kWidth, self.bounds.size.height) taget:delegate action:action];
//            touchImage.image = [UIImage imageNamed:[insterArray objectAtIndex:i]];
            [touchImage sd_setImageWithURL:[NSURL URLWithString:[insterArray objectAtIndex:i]]];
            [self addSubview:touchImage];
            
        }
        //
        [NSTimer scheduledTimerWithTimeInterval:timer target:delegate selector:selector userInfo:nil repeats:YES];
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
